<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>详情页</title>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
${user.username}
<%--<form method="post" enctype="multipart/form-data" action="${pageContext.request.contextPath}/user/upload">--%>
<%--    <input type="file" value="上传" name="file">--%>
<%--    <input type="text"  name="id">--%>
<%--    <input type="submit" value="提交">--%>
<%--</form>--%>
<input type="file" value="上传" name="file" id="fileId">
<button id="btn" onclick="upload()">提交</button>

<img id="image">

</body>
<script>
    function upload(){
            var file=document.getElementById("fileId").files[0];
            var forData=new FormData();
            forData.append("file",file);
            $.ajax({
                url:"${pageContext.request.contextPath}/user/upload2",
                type:"post",
                data:forData,
                // 告诉jQuery不要去设置Content-Type请求头
                contentType: false,
                // 告诉jQuery不要去处理发送的数据
                processData: false,
                success:function (res){
                    console.log(res)
                    $("#image").attr("src",res.fileUrl)
                }
            })
    }
</script>
</html>
